package thefirst.support.model;

import java.io.File;
import java.sql.SQLException;
import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Repository;

import thefirst.common.PagingBean;
@Repository
public class NoticeServiceImpl implements NoticeService {
	@Resource(name="noticeDaoImpl")
	private NoticeDao noticeDao;
	@Override
	public void writeNotice(NoticeVO nvo) throws SQLException {
		noticeDao.writeNotice(nvo);

	}
	@Override
	public NoticeVO showNoticeInfoNoHits(int no) throws SQLException {
		NoticeVO nvo=noticeDao.showNoticeInfoNoHits(no);
		System.out.println("Notice Service:"+nvo);
		return nvo;
	}
	@Override
	public NoticeListVO getNoticeList(String pageNo) throws SQLException {
		if(pageNo==null||pageNo==""){
			pageNo="1";
		}
		List<NoticeVO> list=noticeDao.getNoticeList(pageNo);
		int total=noticeDao.totalNoticeContent();
		PagingBean paging=new PagingBean(total, Integer.parseInt(pageNo));
		NoticeListVO nList=new NoticeListVO(list,paging);
		return nList;
	}
	@Override
	public NoticeVO showNoticeInfo(int no) throws SQLException {
		int result=noticeDao.updateHits(no);
		System.out.println("update hits:"+result);
		NoticeVO nvo=noticeDao.showNoticeInfoNoHits(no);
		System.out.println("test show");
		System.out.println("test show:"+nvo);
		return nvo;
	}
	@Override
	public int updateNotice(NoticeVO nvo) throws SQLException {
		return noticeDao.updateNotice(nvo);
	}
	@Override
	public void deleteNotice(int no) throws SQLException {
		noticeDao.deleteNotice(no);
	}
	@Override
	public int updateNoticeNoFile(int no) throws SQLException {
		return noticeDao.updateNoticeNoFile(no);
	}
	@Override
	public void deleteFile(String savFileName) throws Exception {
		File file=new File(savFileName);
		file.delete();
	}

}
